package com.ruoyi.apduParse.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.apduParse.vo.ApduTableVo;
import com.ruoyi.apduParse.service.IApduTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * APDU指令Controller
 *
 * @author 刘梦豪
 * @date 2024-10-25
 */
@Api(tags = "APDU指令Controller")
@RestController
@RequestMapping("/apduSystem/apdu")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ApduTableController extends BaseController {

    private final IApduTableService apduTableService;

    @ApiOperation("查询APDU指令列表")
    @PreAuthorize("@ss.hasPermi('apduSystem:apdu:list')")
    @GetMapping("/list")
    public TableDataInfo<ApduTableVo> list(ApduTableVo entity) {
        return apduTableService.queryList(entity);
    }

    @ApiOperation("查询APDU指令所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ApduTableVo entity) {
        return AjaxResult.success("查询成功", apduTableService.queryAll(entity));
    }

    @ApiOperation("导出APDU指令列表")
    @PreAuthorize("@ss.hasPermi('apduSystem:apdu:export')")
    @Log(title = "APDU指令", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApduTableVo entity) {
        List<ApduTableVo> list = apduTableService.queryAll(entity);
        ExcelUtil<ApduTableVo> util = new ExcelUtil<>(ApduTableVo.class);
        util.exportExcel(response, list, "APDU指令数据");
    }

    @ApiOperation("获取APDU指令详细信息")
    @PreAuthorize("@ss.hasPermi('apduSystem:apdu:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", apduTableService.queryById(id));
    }

    @ApiOperation("新增APDU指令")
    @PreAuthorize("@ss.hasPermi('apduSystem:apdu:add')")
    @Log(title = "APDU指令", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ApduTableVo entity) {
        return toAjax(apduTableService.save(entity));
    }

    @ApiOperation("修改APDU指令")
    @PreAuthorize("@ss.hasPermi('apduSystem:apdu:edit')")
    @Log(title = "APDU指令", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ApduTableVo entity) {
        return toAjax(apduTableService.updateById(entity));
    }

    @ApiOperation("删除APDU指令")
    @PreAuthorize("@ss.hasPermi('apduSystem:apdu:remove')")
    @Log(title = "APDU指令", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(apduTableService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
